package com.xzx.shop_front_api.service.impl;

import com.xzx.shop_front_api.entity.News;
import com.xzx.shop_front_api.mapper.NewsMapper;
import com.xzx.shop_front_api.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsMapper newsMapper;

    @Override
    public int addNews(News news) {
        news.setCreateTime((int)(System.currentTimeMillis() / 1000));
        return newsMapper.insert(news);
    }

    @Override
    public News getNewsById(Long id) {
        return newsMapper.selectById(Math.toIntExact(id));
    }

    @Override
    public int deleteNewsById(Long id) {
        return newsMapper.deleteById(Math.toIntExact(id));
    }

    @Override
    public List<News> getAllNews() {
        return newsMapper.selectAll();
    }
}
